package tr.edu.bilgi.videocs.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DatabaseHelper extends SQLiteOpenHelper {
  private static final String TAG = "DatabaseHelper";
  private static final String DATABASE_NAME = "videos";
  private static final int DATABASE_VERSION = 1;
  
  private static final String CREATE_SQL = 
      "create table speakers( " +
  		"id integer primary key autoincrement," +
  		"name text);" +
  		
  		"create table videos (" +
  		"id text primary key," +
  		"title text," +
  		"speaker_id integer," +
  		"series_id integer" +
  		");" +
  		
  		"create table series (" +
  		"id integer primary key autoincrement," +
  		"name text" +
  		");";
  
  private static final String DROP_TABLES_SQL = "drop table if exists speakers;" +
  		"drop table if exists videos;" +
  		"drop table if exists series;";

  public DatabaseHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
  }

  @Override
  public void onCreate(SQLiteDatabase db) {
    db.execSQL(CREATE_SQL);
    Log.i(TAG, "Tables are created");
  }

  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL(DROP_TABLES_SQL);
  }
}
